// 注册按钮
const Registration = document.querySelector('.btn-inner--text');
// 表单fom元素
const form = document.querySelector('form');
// boostrap提示内容元素
const mytoastText = document.querySelector('.toast-body');
// 账号输入框元素
const number = document.querySelector('#input-email');
// 密码输入框元素
const Password = document.querySelector('#input-password');
// 注册和登录按钮dom元素
const request = document.querySelector('.btn-inner--text');
// 注册
form.addEventListener('submit', async function (e) {
    e.preventDefault();
    console.log(123);
    const data = serialize(form, { hash: true, empty: true })
    if (request.innerText === "注册") {
        if (number.value !== '' && Password.value !== '') {
            const result = await axios({
                url: "/register",
                method: "POST",
                data
            })
            // 显示提示框
            myToast.show()
            // 修改提示内容
            document.querySelector('#myToast .toast-body').innerHTML = "注册成功"
            console.log(result);
            // 延时两秒登录
            setTimeout(() => {
                location.href = "login.html";
            }, 2000)
        } else {
            // 显示提示框
            myToast.show()
            document.querySelector('#myToast .toast-body').innerHTML = "账号或密码不能为空"
        }

    } else if (request.innerText === "登录") {
        // form.addEventListener('submit', async function (e) {
        // const data = serialize(form, { hash: true, empty: true })
        if (number.value !== '' && Password.value !== '') {
            const result = await axios({
                url: "/login",
                method: "POST",
                data
            })
            // 显示提示框
            myToast.show()
            // 修改提示内容
            document.querySelector('#myToast .toast-body').innerHTML = "登录成功"
            localStorage.setItem("msc90", result.data.data.token)
            setTimeout(() => {
                location.href = "student.html";
            }, 2000)
            // localStorage.setItem("msc90", result.data.token)
            // 存储一个token


        } else {
            // 显示提示框
            myToast.show()
            document.querySelector('#myToast .toast-body').innerHTML = "账号或密码不能为空"
        }
        // })

    }
})
// 登录

